package com.xt.base.action;   
  
import org.apache.log4j.Logger;

import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.Interceptor;
public class ExceptionInterceptor implements Interceptor{   
	private static final long serialVersionUID = -217254981119604838L;
	private static Logger log = Logger.getLogger(ExceptionInterceptor.class);
	public static final String exception= "exception";   
  
    public void destroy() {   
  
    }   
  
    public void init(){   
  
    }   
  
    public String intercept(ActionInvocation av) throws Exception {
    	log.debug("ExceptionIntercept");
    	String forward = "";
    	String errorMessage = null;
    	try{
    		forward = av.invoke();
    	}catch(NullPointerException e){
    		forward = exception;
    		e.printStackTrace();
    		errorMessage = "空指针异常！请与管理员联系！";
    	}catch(Exception e){
    		forward = exception;
    		e.printStackTrace();
    		errorMessage = e.getMessage()+"！ 请与管理员联系！";
    	}
    	ActionContext.getContext().put("errorMessage",errorMessage);
       return  forward;   
  
    }   
  
}  